#include "head.h"


// 分析命令
cmd_t analyse(char* cmd)
{
    char tmp[100] = {0};
    char* p = cmd;
    char* q = tmp;

    while(1)
    {
        while(*p == ' ')   ++p;
        
        while( (*q = *p) != ' ' && (*q = *p) != '\n')
        {
            ++q;
            ++p;
        }    

        if(*p == '\n')
        {
            *q = '\0';
            break;
        }      

        ++q;++p;
    }

    bzero(cmd, strlen(cmd));
    strcpy(cmd, tmp);

    if(memcmp(cmd, "cd", 2) == 0)
        return CD;
    if(memcmp(cmd, "ls", 2) == 0)
        return LS;
    if(memcmp(cmd, "mkdir", 5) == 0)
        return MKDIR;
    if(memcmp(cmd, "RM", 2) == 0)
        return RM;
    if(memcmp(cmd, "pwd", 3) == 0)
        return PWD;
    if(memcmp(cmd, "up", 2) == 0)
        return UP;
    if(memcmp(cmd, "cd", 2) == 0)
        return CD;
    if(memcmp(cmd, "cd", 2) == 0)
        return CD;  

    return ERROR;  
}